import { Component, OnInit } from '@angular/core';
import { NavController } from '@ionic/angular';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { ToolService } from 'src/app/service/tool.service';

@Component({
  selector: 'app-betsuccess',
  templateUrl: './betsuccess.page.html',
  styleUrls: ['./betsuccess.page.scss'],
})
export class BetsuccessPage implements OnInit {
  public sum = { "cnt": 0, "sum": 0 };
  public orderArr: any[] = [];
  private playCode: any; //彩种的code
  private lotName: any;
  private lotteryId: any;
  constructor(private navCtrl: NavController, private activeRoute: ActivatedRoute,private router:Router) { }

  ngOnInit() {
    let that = this;
    this.activeRoute.queryParams.subscribe((params: Params) => {
      let tempDeal=JSON.parse(ToolService.paramAESDecrypt(params['p']));
      let tempRes = JSON.parse(tempDeal['res']);
      that.playCode = tempDeal['playCode'];
      that.lotName = tempDeal['lotName'];
      that.lotteryId = tempDeal['lotteryId'];
      that.sum = tempRes.sum;
      that.orderArr = tempRes.orders;
    });
  }
  /**
   * 关闭成功的页面
   */
  closePage() {
    let that=this;
    let param = "{\"code\":\"" + that.playCode + "\",\"name\":\"" + that.lotName + "\",\"lotteryId\":\"" + that.lotteryId + "\"}";
    this.router.navigate(['/lotdetail'],{
        queryParams:{ "p": ToolService.paramAESEncrypt(param)}
    });
  }
  /**
   * 跳转到注单详细页里面
   */
  betDetailPage() {
    this.navCtrl.navigateForward("/tabs/report");
  }

}
